package com.ala4.oxcafe.boot.provider;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;
import java.util.List;

/**
 * @author PING
 * @date 2025/8/11 22:30
 */
public class WeChatAuthenticationToken implements Authentication {

    /**
     * 微信用户CODE
     */
    private final Object weChatCode;

    /**
     * 用户信息
     */
    private Object principal;

    public static WeChatAuthenticationToken unauthenticated(Object weChatCode) {
        return new WeChatAuthenticationToken(weChatCode);
    }

    public WeChatAuthenticationToken(Object weChatCode) {
        this.weChatCode = weChatCode;
    }


    public WeChatAuthenticationToken(Object weChatCode, Object principal, Collection<? extends GrantedAuthority> authorities) {
        this.weChatCode = weChatCode;
        this.principal = principal;
        this.setAuthenticated(true);
    }

    public static WeChatAuthenticationToken authenticated(Object credentials, Object principal, Collection<? extends GrantedAuthority> authorities) {
        return new WeChatAuthenticationToken(credentials, principal, authorities);
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return List.of();
    }

    @Override
    public Object getCredentials() {
        return this.weChatCode;
    }

    @Override
    public Object getDetails() {
        return null;
    }

    @Override
    public Object getPrincipal() {
        return this.principal;
    }

    @Override
    public boolean isAuthenticated() {
        return false;
    }

    @Override
    public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {

    }

    @Override
    public String getName() {
        return (String) this.weChatCode;
    }
}
